<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>博客及评论管理</title>
</head>
<style type="text/css">
.tbyd {
	position: relative;
	left: 0px;
	top: 0px;
}

table tr th {
	width: 50px;
	height: 50px;
	font-size: 20px;
}

.tbyd .tenakd {
	width: 300px;
}

.xzcz {
	position: absolute;
	left: 400px;
	top: 50px;
}

.jtcz01 {
	position: absolute;
	left: 500px;
	top: 50px;
}

.jtcz02 {
	position: absolute;
	left: 580px;
	top: 50px;
}

.jtcz03 {
	position: absolute;
	left: 660px;
	top: 50px;
}

.jtcz04 {
	position: absolute;
	left: 740px;
	top: 50px;
}

.addbbookk {
	border: 1px solid gray;
	background-color: #F5F5F5;
	width: 705px;
	height: 435px;
	position: absolute;
	left: 400px;
	top: 100px;
	text-align: center;
}

.delebbookk {
	border: 1px solid gray;
	background-color: #F5F5F5;
	width: 500px;
	height: 150px;
	position: absolute;
	left: 500px;
	top: 100px;
	text-align: center;
}

.changebbookk {
	border: 1px solid gray;
	background-color: #F5F5F5;
	width: 700px;
	position: absolute;
	left: 400px;
	top: 100px;
}

a {
	color: black;
	text-decoration: none;
}

a:hover {
	color: red;
}

.zwxgyd {
	position: relative;
	top: -130px;
}
.pldisappear{
    border: 1px solid gray;
	background-color: #F5F5F5;
	width: 364px;
}
</style>
<body onmousemove="pos()">
	<%!
	    private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	    private static final String DB_USER = "root";
	    private static final String DB_PWD = "ZLWL";
		int setnum = 0;
	%>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		Connection conn;
		try {
			conn = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
			Statement stmt = conn.createStatement();
			String sqlz = "select count(id) total from blog";
			ResultSet rsz = stmt.executeQuery(sqlz);
			while (rsz.next()) {
				int getnum = rsz.getInt(1);
				setnum = getnum;
			}
			String sqlx = "select * from blog";
			ResultSet rsx = stmt.executeQuery(sqlx);
			Map<String, String> hashMap2 = new HashMap<String, String>();
			int j = 1;
			while (rsx.next()) {
				hashMap2.put("id" + j, rsx.getString("id"));
				hashMap2.put("title" + j, rsx.getString("title"));
				hashMap2.put("publish_time" + j, rsx.getString("publish_time"));
				hashMap2.put("content" + j, rsx.getString("content"));
				hashMap2.put("read_count" + j, rsx.getString("read_count"));
				hashMap2.put("comment_count" + j, rsx.getString("comment_count"));
				j++;
			}
			response.getWriter().append("<table border='1' class='tbyd'>");
			response.getWriter().append("<tr>");
			response.getWriter().append("<th>ID</th>");
			response.getWriter().append("<th class='tenakd'>博客</th>");
			response.getWriter().append("</tr>");
			response.getWriter().append("</table>");
			int k = 1;
			while (k < (setnum + 1)) {
				int ii = 1;
				String sqlha = "select * from review where bei_id = " + hashMap2.get("id" + k);
				ResultSet rsha = stmt.executeQuery(sqlha);
				while (rsha.next()) {
					hashMap2.put("review_id" + ii, rsha.getString("id"));
					hashMap2.put("reviewer" + ii, rsha.getString("reviewer"));
					hashMap2.put("revew_time" + ii, rsha.getString("revew_time"));
					hashMap2.put("review_content" + ii, rsha.getString("review_content"));
					hashMap2.put("bei_id" + ii, rsha.getString("bei_id"));
					hashMap2.put("ping_id" + ii, rsha.getString("ping_id"));
					//System.out.println("**********************************");
					//System.out.println("review_id:" + hashMap2.get("review_id" + ii));
					//System.out.println("reviewer:" + hashMap2.get("reviewer" + ii));
					//System.out.println("revew_time:" + hashMap2.get("revew_time" + ii));
					//System.out.println("review_content:" + hashMap2.get("review_content" + ii));
					//System.out.println("bei_id:" + hashMap2.get("bei_id" + ii));
					//System.out.println("ping_id:" + hashMap2.get("ping_id" + ii));
					//System.out.println("**********************************");
					ii++;
				}
			    rsha.close();
				response.getWriter().append("<table border='1' class='tbyd' id='" + hashMap2.get("id" + k) + "'>");
				response.getWriter().append("<tr class='mouseo'>");
				response.getWriter().append("<th>");
				response.getWriter().append(hashMap2.get("id" + k));
				response.getWriter().append("</th>");
				response.getWriter().append("<th class='tenakd' lang='" + hashMap2.get("title" + k) 
				+ "'title='" + hashMap2.get("publish_time" + k) 
				+ "' id='" + hashMap2.get("content" + k)
				+ "' abbr='" + hashMap2.get("read_count" + k) 
				+ "' axis='" + hashMap2.get("comment_count" + k) 
				+ "' onmouseover='getEventTrigger(event)'>");
				response.getWriter().append(hashMap2.get("title" + k));
				response.getWriter().append("</th>");
				response.getWriter().append("</tr>");
				response.getWriter().append("</table>");
				int iii = 1;
				while (iii < ii) {
					response.getWriter().append("<div class='pldisappear pldisappear" + hashMap2.get("id" + k) + "'>");
					response.getWriter().append("<span>此评论ID<b>:" + hashMap2.get("review_id" + iii) + "</b></span><hr>");
					response.getWriter().append("<span>评论者:" + hashMap2.get("reviewer" + iii) + "</span><hr>");
					response.getWriter().append("<span>评论内容:<br>" + hashMap2.get("review_content" + iii) + "</span><hr>");
					response.getWriter().append("<span>评论时间:" + hashMap2.get("revew_time" + iii) + "</span>");
					response.getWriter().append("</div>");
					iii++;
				}
				//response.getWriter().append("<img class='classimg" + k + "' id='1' name='2'>");
				//<img alt='Pulpit Rock' width='www' height='hhh' id='iii' name='nnn'>
				//<br><span id='p1' onmouseover='getEventTrigger(event)'>target.event</span>
				k++;
			}
			rsx.close();
			rsz.close();
			stmt.close();
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	%>
	<button class="xzcz">选择操作</button>
	<button class="jtcz jtcz01 jtcz1">添加博客</button>
	<button class="jtcz jtcz02 jtcz2">删除博客</button>
	<button class="jtcz jtcz03 jtcz3">修改博客</button>
	<button class="jtcz jtcz04 jtcz4">博客评论管理</button>
	<div class="addbbookk">
		<span><a target="center" href="blog_add.jsp">发表博客</a></span><br>
		<iframe src="linshinew.jsp" height="400" width="700" name="center"></iframe>
	</div>
	<div class="delebbookk">
		<br> <br> <br>
		<form action="/deletebbookk" method="post">
			<span>输入要删除的博客的ID:</span> <input type="text" name="deletebbookkid" />
			<button type="submit">提交</button>
		</form>
	</div>
	<div class="changebbookk">
		<span>博客标题:</span><br>&nbsp;&nbsp;&nbsp; <span id="show"></span><br>
		<span>博客正文:</span><br>&nbsp;&nbsp;&nbsp; <span id="showcontent"></span><br>
		<span>博客发表时间:</span><br>&nbsp;&nbsp;&nbsp; <span id="showcontenta"></span><br>
		<span>博客阅读量:</span><br>&nbsp;&nbsp;&nbsp; <span id="showcontentb"></span><br> 
		<span>博客评论量:</span><br>&nbsp;&nbsp;&nbsp; <span id="showcontentc"></span><br> <br> <br>
		<button class="chuxianbbkxgkz">修改博客</button>
		<button class="chuxianpplxgkz">此博客评论</button>
		<button class="xxxchuxianpplxgkz1">增加此博客评论</button>
		<button class="xxxchuxianpplxgkz2">删除此博客评论</button>
		<button class="xxxchuxianpplxgkz3">修改此博客评论</button>
		<hr color="white" style="height: 30px;">
		<div class="bbkxgkz">
			<form action="/changebbookkss" method="post" name="forids">
				<span>标题修改为:</span> <input type="text" name="bktitlexg" /><br>
				<span class="zwxgyd">正文修改为:</span>
				<textarea name="bkcontentxg" rows="10" cols="50"></textarea>
				<br><button type="submit">提交</button>
				<br> <input type="hidden" name="bkidsxg" />
			</form>
		</div>
		<div class="pplxgkz">
			<form action="/changepingl" method="post">
				<span>要修改的评论ID为:</span> <input type="text" name="idreviewerxg" /><br>
				<span class="zwxgyd">评论内容要修改为:</span>
				<textarea name="pinglcontentxg" rows="10" cols="50"></textarea>
				<br><button type="submit">提交</button>
			</form>
		</div>
		<div class="pplzjkz">
		    <form action="/addpingl" method="post" name="benbbkdidadd">
                <span class="zwxgyd">输入新评论内容:</span>
                <textarea name="newpplneir" rows="10" cols="50"></textarea><br><br>
                <button type="submit">提交</button>
                <input type="hidden" name="bkidsadd" />
            </form>
        </div>
		<div class="pplsckz">
		    <form action="/deletepingl" method="post" name="benbbkdid">
                <span>输入要删除的评论的ID:</span>
                <input type="text" name="deleteppldid" />
                <button type="submit">提交</button>
                <input type="hidden" name="bkidsdelete" />
            </form>
		</div>
	</div>
	<script type='text/javascript' src='/static/js/jquery.min.js'></script>
	<script type="text/javascript">
$(document).ready(function(){
	$(".jtcz").hide();
    $(".xzcz").click(function(){
    	$(".pldisappear").fadeOut();
    	$(".addbbookk").fadeOut();
    	$(".delebbookk").fadeOut();
    	$(".changebbookk").fadeOut();
        $(".jtcz").slideToggle();
        })
});
$(document).ready(function(){
	$(".addbbookk").hide();
    $(".jtcz1").click(function(){
    	$(".pldisappear").fadeOut();
        $(".delebbookk").fadeOut();
        $(".changebbookk").fadeOut();
        $(".addbbookk").slideToggle();
        })
});
$(document).ready(function(){
	$(".delebbookk").hide();
    $(".jtcz2").click(function(){
    	$(".pldisappear").fadeOut();
        $(".addbbookk").fadeOut();
        $(".changebbookk").fadeOut();
        $(".delebbookk").slideToggle();
        })
});
$(document).ready(function(){
	$(".changebbookk").hide();
    $(".jtcz3").click(function(){
    	$(".pldisappear").fadeOut();
        $(".addbbookk").fadeOut();
        $(".delebbookk").fadeOut();
        $(".changebbookk").slideToggle();
        })
});
$(document).ready(function(){
	$(".bbkxgkz").hide();
    $(".chuxianbbkxgkz").click(function(){
    	$(".pldisappear").fadeOut();
    	$(".xxxchuxianpplxgkz1").fadeOut();
    	$(".xxxchuxianpplxgkz2").fadeOut();
    	$(".xxxchuxianpplxgkz3").fadeOut();
    	$(".pplxgkz").fadeOut();
    	$(".pplzjkz").fadeOut();
    	$(".pplsckz").fadeOut();
        $(".bbkxgkz").slideToggle();
        })
});
$(document).ready(function(){
	$(".xxxchuxianpplxgkz1").hide();
	$(".xxxchuxianpplxgkz2").hide();
	$(".xxxchuxianpplxgkz3").hide();
	$(".pplxgkz").hide();
	$(".pplzjkz").hide();
	$(".pplsckz").hide();
    $(".chuxianpplxgkz").click(function(){
    	$(".bbkxgkz").fadeOut();
    	$(".pplxgkz").fadeOut();
    	$(".pplzjkz").fadeOut();
    	$(".pplsckz").fadeOut();
        $(".xxxchuxianpplxgkz1").slideToggle();
        $(".xxxchuxianpplxgkz2").slideToggle();
        $(".xxxchuxianpplxgkz3").slideToggle();
        })
});
$(document).ready(function(){
    $(".xxxchuxianpplxgkz3").click(function(){
    	$(".pplzjkz").fadeOut();
    	$(".pplsckz").fadeOut();
        $(".pplxgkz").slideToggle();
        })
});
$(document).ready(function(){
    $(".xxxchuxianpplxgkz2").click(function(){
    	$(".pplxgkz").fadeOut();
    	$(".pplzjkz").fadeOut();
        $(".pplsckz").slideToggle();
        })
});
$(document).ready(function(){
    $(".xxxchuxianpplxgkz1").click(function(){
    	$(".pplxgkz").fadeOut();
    	$(".pplsckz").fadeOut();
        $(".pplzjkz").slideToggle();
        })
});
var fiernums = "0";
function fnGetTable(oEl) {
	try {
		while (null != oEl && oEl.tagName != "TABLE") {
			oEl = oEl.parentElement;
		}
		return oEl;
	} catch (e) {
		return null;
	}
}
function pos() {
	try {
		oElement = document.elementFromPoint(event.x, event.y);
		oElement = fnGetTable(oElement);
		if (oElement.tagName == "TABLE")
			//show.innerText = oElement.id;
		    fiernums = oElement.id;
	} catch (e) {
	}
}
$(document).ready(function(){
	$(".pldisappear").hide();
    $(".chuxianpplxgkz").click(function(){
    	$(".pldisappear").fadeOut();
        $(".pldisappear" + fiernums).slideToggle();
        })
});
$(document).ready(function(){
	$(".pldisappear").hide();
    $(".jtcz4").click(function(){
        $(".addbbookk").fadeOut();
        $(".delebbookk").fadeOut();
        $(".changebbookk").slideToggle();
        $(".xxxchuxianpplxgkz1").slideToggle();
        $(".xxxchuxianpplxgkz2").slideToggle();
        $(".xxxchuxianpplxgkz3").slideToggle();
        $(".pldisappear" + fiernums).slideToggle();
        })
});
function getEventTrigger(event){ 
    x=event.target; 
    document.getElementById('showcontent').innerHTML = x.id;
    document.getElementById('showcontenta').innerHTML = x.title;
    document.getElementById('show').innerHTML = x.lang;
    document.getElementById('showcontentb').innerHTML = x.abbr;
    document.getElementById('showcontentc').innerHTML = x.axis;
    dylcs();
    dylcsid();
    dylcsidss();
}
function nputt(bkidsxg){
	document.forids.bkidsxg.value = bkidsxg;
}
function dylcs(){
	nputt(fiernums);
}
function nputtid(bkidsdelete){
	document.benbbkdid.bkidsdelete.value = bkidsdelete;
}
function dylcsid(){
	nputtid(fiernums);
}
function nputtidss(bkidsadd){
	document.benbbkdidadd.bkidsadd.value = bkidsadd;
}
function dylcsidss(){
	nputtidss(fiernums);
}
<%-- 
var showcontent = new Array()
$(document).ready(function(){
	$(".mouseo").mouseover(function(){
		//alert("alt: " + $("img").attr("alt"));
		//alert("width: " + $("img").attr("width"));
		//alert("height: " + $("img").attr("height"));
		//alert("id: " + $("img").attr("id"));
		//alert("name: " + $("img").attr("name"));
		var num = 1;
		var smnum = <%=setnum%>
		var showcontenta = new Array()
		while(num < smnum){
		showcontent[num] = $(".classimg" + num).attr("id");
		showcontenta[num] = $(".classimg" + num).attr("name");
		document.getElementById('showcontent').innerHTML = showcontent[num];
		document.getElementById('showcontenta').innerHTML = showcontenta[num];
		console.log("showcontent" + num + ":" + showcontent[num]);
		num ++;
		}
	});
}); 
--%>
</script>
</body>
</html>